package demo05;

public class FizzBuzz {
	private int n;
	private int count = 1;
    public FizzBuzz(int n){
        this.n=n;
    }
	public synchronized void fizz() {
        while(!(count%3==0 && count%5!=0) &&count<n){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        if(count%3==0 && count%5!=0&& count<=n){
            System.out.print("fizz ");
            count++;
            notifyAll();
        }
    }         
    public synchronized void buzz() {
        while(!(count%5==0 && count%3!=0) && count<=n){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        if(count%5==0 && count%3!=0&& count<=n){
            System.out.print("buzz ");
            count++;
            notifyAll();
        }
    }       
    public synchronized void fizzbuzz() {
        while(!(count%3==0 && count%5==0) && count<=n){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        if(count%3==0 && count%5==0 && count<=n){
            System.out.print("fizzbuzz ");
            count++;
            notifyAll();
        }
    }  
    public synchronized void number() {
        while(!(count%3!=0 && count%5!=0) && count<=n){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        if(count%3!=0 && count%5!=0&& count<=n){
            System.out.print(count+" ");
            count++;
            notifyAll();
        }
    }     

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getN() {
        return n;
    }
}

